<template>
  <div>
    <el-row>
      <el-col :span="12" id="A-1">
        <div id="A-1-1">下午好！ </div>
      </el-col>
      <el-col :span="12" id="A-2">

      </el-col>
    </el-row>


    <el-form ref="registerForm" :model="registerForm" label-width="80px" style="max-width: 400px; margin: auto;">
      <el-form-item label="*教练名" prop="coachName">
        <el-input v-model="registerForm.coachName"></el-input>
      </el-form-item>
      <el-form-item label="*手机号" prop="coachPhone">
        <el-input v-model="registerForm.coachPhone"></el-input>
      </el-form-item>
      <el-form-item label="*昵称" prop="coachNickName">
        <el-input v-model="registerForm.coachNickName"></el-input>
      </el-form-item>
      <el-form-item label="*密码" prop="coachPassword">
        <el-input type="password" v-model="registerForm.coachPassword"></el-input>
      </el-form-item>
      <el-form-item label="*验证码" prop="code">
        <el-input v-model="registerForm.code"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="sendRegisterCode" >发送注册验证码</el-button>
        <el-button type="primary" @click="register" >点击注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: "coachRegister",
    data() {
      return {
        //教练注册需要的参数
        registerForm: {
          coachName: '',
          coachPhone: '',
          coachNickName: '',
          coachPassword: '',
          code: ""
        },
        registering: false, // 控制注册按钮的 loading 状态
        sendingCode: false // 控制发送验证码按钮的 loading 状态
      }
    },
    methods: {
      //教练注册 发送注册手机号验证码
      sendRegisterCode() {
        this.sendingCode = true;
        this.$http.get("/account/yCoach/sendCoachRegisterCode", {
            params: {
              mobile: this.registerForm.coachPhone
            }
          })
          .then(resp => {
            this.$message.success(resp.data.meg);
          })
      },
      //教练注册接口
      register() {
        console.log(this.registerForm)
        this.$http.post("/account/yCoach/checkCode", this.registerForm).then(resp => {
          console.log(resp.data.data)
          if (resp.data.code == 200) {
            this.$message.success(resp.data.msg);
            //注册成功跳转教练登录接口
            this.$router.push("/CoachLogin");
          } else {
             alert(resp.data.meg);
          }
        })
      }
    },
    created() {

    }
  }
</script>

<style>
  #A-2-2 {
    margin-right: 130px;
  }

  #A-2 {
    background-color: rgb(245, 245, 245);
    border: 1px solid blanchedalmond;
    text-align: right;
    height: 30px;
    border-left: none;
  }

  #A-1-1 {
    text-align: center;
    font-size: 14px;
    margin-left: 0px;
  }

  #A-1 {
    height: 30px;
    background-color: rgb(245, 245, 245);
    border: 1px solid blanchedalmond;
    border-right: none;
  }


  * {
    margin: 0;
    padding: 0;
  }
</style>
